{extend name="public/layout" /}

{block name="title"}新增文档{/block}
{block name="main"}
<div class="pd-20">
    <form action="{:U('documents/update')}" method="post" class="form form-horizontal" id="technique">
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>文章标题：</label>
            <div class="formControls col-10">
                <input type="text" class="input-text" value="{$res.title}" name="title" datatype="*1-200" dragonfly="true" nullmsg="文章标题不能为空" errormsg="请输入分类名称">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">简略标题：</label>
            <div class="formControls col-10">
                <input type="text" class="input-text" value="{$res.brief}" name="brief">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>分类栏目：</label>
            <div class="formControls col-2"> <span class="select-box">
                <select name="sort_id" class="select">
                    {foreach $sort_list as $value}
                    <option value="{$value.id}" {$value['id'] == $res['sort_id'] ?'selected':''}>{$value.sname}</option>
                    {/foreach}
                </select>
                </span> </div>
            <label class="form-label col-2"><span class="c-red">*</span>文章类型：</label>
            <div class="formControls col-2"> <span class="select-box">
                <select name="type" class="select">
                    <option value="1" {$res['type'] == 1 ? 'selected' : ''}>新闻咨询</option>
                    <option value="2" {$res['type'] == 2 ? 'selected' : ''}>帮助类型</option>
                    <option value="3" {$res['type'] == 3 ? 'selected' : ''}>其他类型</option>
                </select>
                </span> </div>
            <label class="form-label col-2">排序值：</label>
            <div class="formControls col-2">
                <input type="text" class="input-text" value="{$res.sort}" name="sort" datatype="n" errormsg="排序值为大于等于0的正整数，越大越靠前">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">关键词：</label>
            <div class="formControls col-10">
                <input type="text" class="input-text" value="{$res.keyword}" name="keyword" datatype="/^.{0,200}$/" errormsg="关键词最大长度不能超过100" />
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">文章摘要：</label>
            <div class="formControls col-10">
                <textarea name="abstract" class="textarea"  placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="textarealength(this,200)">{$res.abstract}</textarea>
                <p class="textarea-numberbar"><em class="textarea-length">0</em>/200</p>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">文章作者：</label>
            <div class="formControls col-2">
                <input type="text" class="input-text" value="{$res.author}" name="author">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">允许评论：</label>
            <div class="formControls col-2 skin-minimal">
                <div class="check-box">
                    <input type="checkbox" id="checkbox-pinglun" name="comment" {$res['comment'] == 1 ? 'checked' : ''} value="1" />
                    <label for="checkbox-pinglun">&nbsp;</label>
                </div>
            </div>
            <label class="form-label col-2">评论开始日期：</label>
            <div class="formControls col-2">
                <input type="text" id="datemin" name="com_starttime" class="input-text Wdate" readonly="readonly" placeholder="点击选择日期" value="{:date('Y-m-d',$res['com_starttime'])}">
            </div>
            <label class="form-label col-2">评论结束日期：</label>
            <div class="formControls col-2">
                <input type="text" id="datemax" name="com_endtime" class="input-text Wdate" readonly="readonly" placeholder="点击选择日期" value="{if condition='$res.com_endtime'}{:date('Y-m-d',$res['com_endtime'])}{/if}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">缩略图：</label>
            <div class="formControls col-10">
                <div class="uploader-thum-container">
                    <div id="fileList" class="uploader-list"></div>
                    <div id="upload"></div>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">文章内容：</label>
            <div class="formControls col-10">
                <script id="editor" type="text/plain" style="width:100%;height:400px;" name="content">{$res.content}</script>
            </div>
        </div>
        <div class="row cl">
            <div class="col-10 col-offset-2">
                <input type="hidden" name="did" value="{$res.id}" />
                <input type="submit" value="保存并提交审核" class="btn btn-primary radius" onclick="getContent()" />
                <button onClick="article_save();" class="btn btn-secondary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存草稿</button>
                <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="js"}
{load href="__ADMIN__/lib/ueditor/1.4.3/ueditor.config.js"/}
{load href="__ADMIN__/lib/ueditor/1.4.3/ueditor.all.min.js"/}
{load href="__ADMIN__/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"/}
{load href="__ADMIN__/lib/Validform/5.3.2/Validform.min.js"/}
{load href="__ADMIN__/lib/Huploadify/jquery.Huploadify.js" /}
{load href="__ADMIN__/lib/laydate/laydate.js" /}
{load href="__ADMIN__/js/H-ui.js"/}
{load href="__ADMIN__/js/H-ui.admin.js"/}
<script type="text/javascript">
$(function(){
    //日期选择器
    laydate({
        elem: '#datemin',
        min: laydate.now(-1),
    });
    laydate({
        elem: '#datemax',
        min: laydate.now(0),
    });
    $("#technique").Validform({
          tiptype:4,
          ajaxPost:true,
          datatype:{
            "*6-20": /^[^\s]{6,20}$/,
          },
          callback:function(data){
            if(data.status == 'y'){
              var index = parent.layer.getFrameIndex(window.name);
              parent.$('.btn-refresh').click();
              parent.location.reload();
              parent.layer.msg('操作成功！',{icon:1});
              parent.layer.close(index);
            }else{
              layer.alert(data.info ? data.info : '500', {
                icon: 2
              })
            }
          }
      });
    var ue = UE.getEditor('editor');

    $('#upload').Huploadify({
            auto:true,  //是否直接上传
            fileTypeExts:'*.jpg;*.png;', //文件格式
            multi:false,  //是否允许上传多个文件
            formData:{did:{$res.id}},  //同时提交的额外数据
            fileSizeLimit:'1MB',  //文件大小限制
            showUploadedPercent:false,//是否实时显示上传的百分比，如20%
            showUploadedSize:true,
            removeTimeout:9999999,
            uploader:'{:U("Documents/fileupload")}',
            buttonClass:'btn btn-primary upload-btn',
        onUploadStart:function(){

        },
        onInit:function(){
            //alert('初始化');
        },
        onUploadComplete:function(file,jsonData){
            var data = JSON.parse(jsonData);
            if(data.status == 'y'){
                layer.alert('上传成功！',{
                    icon:1
                });
            }else{
                layer.alert(data.info,{
                    icon:2
                });
            }

        },
        onDelete:function(file){
            console.log('删除的文件：'+file);
            console.log(file);
        }
    });

});
function getContent() {
    var content = (UE.getEditor('editor').getContent());
    $("#content").html(content);
}


</script>
{if empty($sort_list)}
<script type="text/javascript">
    $(function(){
        layer.msg('没有添加文档分类， 请填写文档分类再操作', {icon: 2},function(){
            location.href = "{:U('sorting/index')}";
        });
    })
</script>
{/if}
{/block}
